package com.example.first.interceptors;

import com.example.first.utils.RetrofitClient;

import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class GlobalHeaderInterceptor implements Interceptor {


    @Override
    public Response intercept(Chain chain) throws IOException {
        //拿到原请求体
        Request originalRequest = chain.request();
        //获取全局请求头
        String token = RetrofitClient.getToken();

        if(token!=null){
            // 添加全局请求头
            Request requestWithHeaders = originalRequest.newBuilder()
                    .header("authentication", token)
                    .build();

            return chain.proceed(requestWithHeaders);
        }else {
            return chain.proceed(originalRequest);
        }



    }
}
